//账户流水列表 0
//账户流水详情 1

define(function(require, exports, module){
	"require:nomunge,exports:nomunge,module:nomunge";
	//异步请求
var wind_async=require('ddf_wind_async');
	
var base=require('component-base');

var history=require('component-history');
	
require('component-page');


var pageIndex=0;

var beginDate,endDate,keyword_s,operType,beginMoney,endMoney,keyRange,queryDate,orderId;

var selectAccountJourId;

var tips_index=0;

/**
 * 初始化参数
 */
function initParams(){
	
	
	beginDate="";
	endDate="";
	operType="";
	beginMoney="";
	endMoney="";
	keyword_s="";
	keyRange="";
	orderId="";
	
}


/**
 * 查询帐号流水列表
 */
exports.init=function(m){
	history.addHis(this,arguments);//增加历史
    window.$ddf_account = m;
		initParams();
		var htmlStr = "";


		htmlStr += '<div id="content-header"><div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href="javascript:void(0)" class="current">账户流水管理</a></div>';
		
//		htmlStr += '<h1>备付金账户余额：<span id="show_balance"></span> &nbsp;&nbsp;元</h1>';
		htmlStr += '</div>';
		htmlStr += '<div class="container-fluid">';
//		htmlStr += '<hr/>';
		htmlStr += '<div class="row-fluid">';
		htmlStr += '<div class="span12">';
		htmlStr += '<div id="alert-tips0" ></div>';
		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title"><span class="icon"><i class="icon-search"></i></span><h5>搜索条件</h5><button type="button" class="label label-success toggle">缩放</button></div>  ';
		htmlStr += '<div class="widget-content nopadding">';
		htmlStr += '<form class="form-horizontal">';
		
		htmlStr += '<div class="control-group"><label class="control-label">创建时间：</label><div class="controls"><input class="span2 m-wrap Wdate" type="text" id="beginDate" onClick=WdatePicker({dateFmt:"yyyy-MM-dd",readOnly:false}) />&nbsp;&nbsp;至&nbsp;&nbsp;<input class="span2 m-wrap Wdate" type="text" id="endDate" onClick=WdatePicker({dateFmt:"yyyy-MM-dd",readOnly:false}) />';
		
		htmlStr += '&nbsp;&nbsp;&nbsp;&nbsp;';
    	htmlStr += '<button type="button" class="btn btn-primary" id="queryDate_0" onclick="$ddf_account.toQueryDate(0)">所有</button>&nbsp;&nbsp;';
    	htmlStr += '<button type="button" class="btn" id="queryDate_1" onclick="$ddf_account.toQueryDate(1)">今天</button>&nbsp;&nbsp;';
    	htmlStr += '<button type="button" class="btn" id="queryDate_2" onclick="$ddf_account.toQueryDate(2)">最近1个月</button>&nbsp;&nbsp;';
    	htmlStr += '<button type="button" class="btn" id="queryDate_3" onclick="$ddf_account.toQueryDate(3)">3个月</button>&nbsp;&nbsp;';
    	htmlStr += '<button type="button" class="btn" id="queryDate_4" onclick="$ddf_account.toQueryDate(4)">1年</button>&nbsp;&nbsp;';
    	htmlStr += '<button type="button" class="btn" id="queryDate_5" onclick="$ddf_account.toQueryDate(5)">1年前</button>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	
    	htmlStr += '<div class="control-group">';
    	htmlStr += '<label class="control-label">流水类型：</label>';
    	htmlStr += '<div class="controls">';
		htmlStr += '<div class="btn-group"><button data-toggle="dropdown" class="btn dropdown-toggle"><span id="orderTypeName">请选择</span>&nbsp;&nbsp;<span class="caret"></span></button><ul class="dropdown-menu" id="orderTypeList"><li><a href="####">请选择</a></li></ul></div>';
    	htmlStr += '</div>';
    	htmlStr += '<label class="control-label">金额：</label><div class="controls"><input class="span2 m-wrap" type="text" id="beginMoney" />&nbsp;&nbsp;至&nbsp;&nbsp;<input class="span2 m-wrap" type="text" id="endMoney" /></div>';
    	htmlStr += '</div>';
    	
    	
    	htmlStr += '<div class="control-group"></div>';
		
    	
    	htmlStr += '<div class="control-group">';
    	htmlStr += '<label class="control-label">关键字：</label>';
    	htmlStr += '<div class="controls">';
    	
    	htmlStr += '<div class="btn-group">';
    	htmlStr += '<button data-toggle="dropdown" class="btn dropdown-toggle"><span id="keyRangeName">请选择</span>&nbsp;&nbsp;<span class="caret"></span></button>';
    	htmlStr += '<ul class="dropdown-menu">';
    	htmlStr += '<li><a href=javascript:$ddf_account.setKeyRange("bill","流水单号")>流水单号</a></li>';
    	htmlStr += '<li><a href=javascript:$ddf_account.setKeyRange("name","流水类型")>流水类型</a></li>';
    	htmlStr += '</ul>';
    	htmlStr += '</div>&nbsp;&nbsp;';
    	htmlStr += '<input class="span3 m-wrap" type="text" id="keyword_s"/>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	
    	htmlStr += '<div class="row-fluid">';
    	htmlStr += '<div class="span6">';
    	htmlStr += '<div class="control-group">';
    	htmlStr += '<label class="control-label">订单编号：</label>';
    	htmlStr += '<div class="controls">';
    	htmlStr += '<input class="span8 m-wrap" type="text" id="orderId"/>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	htmlStr += '</div>';
    	htmlStr += '</div> ';
    	
    	
    	

    	htmlStr += '<div class="form-actions">';
		htmlStr += '<button class="btn btn-primary" type="button" onClick="$ddf_account.searchAccount()">搜索</button>';
		htmlStr += ' <button class="btn btn-info" type="button" onClick="$ddf_account.resetSearchParams()">重置</button>';
		htmlStr += '</div>        ';
		htmlStr += '</form>';
		htmlStr += '</div>';
		htmlStr += '</div> ';
		
		htmlStr += '<div class="widget-box">';
		htmlStr += '<div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>';
		htmlStr += '<h5>账户流水列表</h5>';
		htmlStr += '</div>';
		htmlStr += '<div class="widget-content nopadding dataTables_wrapper">';
		htmlStr += '<table class="table table-bordered data-table">';
		htmlStr += '<thead>';
		htmlStr += '<tr>';
		htmlStr += '<th>序号</th>';
		htmlStr += '<th>创建时间</th>';
		htmlStr += '<th>流水单号</th>';
		htmlStr += '<th>订单号</th>';
		htmlStr += '<th>流水类型</th>';
		htmlStr += '<th>金额（元）</th>';
		htmlStr += '<th>余额（元）</th>';
		htmlStr += '<th>操作</th>';
		htmlStr += '</tr>';
		htmlStr += '</thead>';
		htmlStr += '<tbody id="accountList">';
		htmlStr += '</tbody>';
		htmlStr += '</table>';
		htmlStr += '<div id="footPageDiv0">';

		htmlStr += '</div>';
		htmlStr += '</div>';
		htmlStr += '</div>  ';
		htmlStr += '</div>';
		htmlStr += '</div> ';
		htmlStr += '</div> ';

		showDiv("content0");

		$("#content0").html(htmlStr);
		
		getOperTypeList();
		
		getAccountList(1,10,beginDate,endDate,keyword_s,operType,beginMoney,endMoney,keyRange,queryDate,orderId);

}


/**
 * 查询订单列表
 * @param pageNumber
 * @param username
 * @param mobile
 */
function getAccountList(pageNumber,pageSize,beginDate,endDate,keyword_s,operType,beginMoney,endMoney,keyRange,queryDate,orderId){
	
	var params={
			"page.pageNumber":pageNumber,
			"beginDate":beginDate,
			"endDate":endDate,
			"operType":operType,
			"beginMoney":beginMoney,
			"endMoney":endMoney,
			"keyRange":keyRange,
			"keyword_s":keyword_s,
			"queryDate":queryDate,
			"orderId":orderId,
			"page.pageSize":pageSize
	        };
	
	base.showLoading();
	
	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.account.getQueryAccount,params));
		
		getAccountListCallBack(data);
		
	}))().start();
	
}

/**
 * 查询订单列表_回调函数
 */
function getAccountListCallBack(data){
	
	
	if(data["code"]==1){


	var htmlStr = "";
	
	$("#show_balance").html(data["balance"]);

	for (var i = 0; i < data["accountListData"].length; i++) {

		htmlStr += '<tr>';
		htmlStr += '<td>' +getSequence(data["pageNumber"],i+1) + '</td>';
		htmlStr += '<td>'+data["accountListData"][i]["createTime"]+'</td>';
		htmlStr += '<td>'+data["accountListData"][i]["accountJourId"]+'</td>';
		htmlStr += '<td>'+data["accountListData"][i]["orderId"]+'</td>';
		htmlStr += '<td>'+data["accountListData"][i]["operName"]+'</td>';
		htmlStr += '<td>'+parseFloat(data["accountListData"][i]["amount"])+'</td>';
		htmlStr += '<td>'+parseFloat(data["accountListData"][i]["balance"])+'</td>';
		
		if(data["accountListData"][i]["operCode"]==4){
			htmlStr += '<td><a href=javascript:$ddf_account.loadAccountDetail("'+data["accountListData"][i]["accountJourId"]+'")>详情</a></td>';
		}else{
			htmlStr += '<td>----</td>';
		}
		
		htmlStr += '</tr>';
	}

	$("#accountList").html(htmlStr);
	
	 $('#footPageDiv0').ddf_pagination(data["pageSize"],data["pageNumber"],data["totalCount"],data["totalPage"],{  
		 
		 changePageCallback:function(pageSize,page){  
			 getAccountList(page,pageSize,beginDate,endDate,keyword_s,operType,beginMoney,endMoney,keyRange,queryDate,orderId)

		 },
		 changePageSizeCallBack:function(pageSize){
			 getAccountList(1,pageSize,beginDate,endDate,keyword_s,operType,beginMoney,endMoney,keyRange,queryDate,orderId)
     	 
		 } 
     }); 

	}else{
		
		 base.tips_error(data["message"]);
	}

	base.cancelLoading();
	
}

/**
 * 重置参数
 */
function resetSearchParams(){
	
	beginDate="";
	endDate="";
	keyword_s="";
	operType="";
	beginMoney="";
	endMoney="";
	keyRange="";
	queryDate="";
	orderId="";
	
	$("#beginDate").val("");
	
	$("#endDate").val("");
	
	$("#beginMoney").val("");
	
	$("#endMoney").val("");
	
	$("#orderId").val("");
	
	$("#keyword_s").val("");
	
	$("#orderTypeName").html("请选择");
	
	$("#keyRangeName").html("请选择");
	
	//设置固定日期的样式
	for (var i = 0; i < 6; i++) {
		$("#queryDate_" + i).removeClass("btn-primary"); 
	}
	
	$("#queryDate_0").addClass("btn-primary");
}


/**
 * 搜索账户流水
 */
function searchAccount(){
	
	keyword_s=$("#keyword_s").val();
	
	beginDate=$("#beginDate").val();
	
	endDate=$("#endDate").val();
	
	beginMoney=$("#beginMoney").val();
	
	endMoney=$("#endMoney").val();
	
	orderId=$("#orderId").val();
	
	if(keyword_s==null||keyword_s==""){
		keyRange="";
	}
	if(queryDate=="0"){
		queryDate="";
	}
	
	if(!base.checkDate(beginDate,endDate)){
		return;
	}
	
	if(!(beginMoney==""&&endMoney=="")){
		if(beginMoney==""){
			base.tips_error("开始金额不能为空");
			return;
		}
		if(endMoney==""){
			base.tips_error("结束金额不能为空");
			return;
		}
	}
	if(parseFloat(beginMoney)>parseFloat(endMoney)){
		base.tips_error("开始金额不能大于结束金额");
		return;
	}
	
	getAccountList(1,pageSize,beginDate,endDate,keyword_s,operType,beginMoney,endMoney,keyRange,queryDate,orderId);
	
}


/**
 *查看账户流水详细信息
 * @param versionId
 */
function loadAccountDetail(_selectAccountJourId){
	history.addHis(this,arguments);//增加历史
	selectAccountJourId=_selectAccountJourId;
	var htmlStr="";
	
	htmlStr += '<div id="content-header">';
	htmlStr += '<div id="breadcrumb"> <a href=javascript:load("'+ddf.index.index_js+'",1,"$ddf_index.loadIndex","") title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a><a href=javascript:$ddf_account.showDiv("content0")>账户流水管理</a><a href="javascript:void(0)" class="current">账户流水详情</a></div>';
	htmlStr += '<h1>账户流水详情</h1>';
	htmlStr += '</div>    ';

	htmlStr += '<div class="container-fluid">';
	htmlStr += '<hr/>';
	htmlStr += '<div class="row-fluid">';
	htmlStr += '<div class="span12">';
	htmlStr += '<div id="alert-tips1" ></div>';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title">';
	htmlStr += '<span class="icon"><i class="icon-reorder"></i></span>';
	htmlStr += '<h5>操作</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content">';
	htmlStr += ' <button type="button" class="btn btn-info" onClick=$ddf_account.showDiv("content0")>返回</button>';
	htmlStr += '</div>            ';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title">';
	htmlStr += '<span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>交易跟踪</h5>';
	htmlStr += '</div>';
	htmlStr += '<div class="widget-content">';
	htmlStr += '<p><span>提现申请状态：</span><span id="applystautusname"></span></p>';
	//htmlStr += '<p><span>订单处理状态：</span><span id="settleresult"></span></p>';
	htmlStr += '</div>';
	htmlStr += '</div>';
	htmlStr += '<hr>';
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title">';
	htmlStr += '<span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>订单申请信息</h5>';
	htmlStr += '</div>        ';
	htmlStr += '<div class="widget-content nopadding dataTables_wrapper">';
	htmlStr += '<table class="table table-bordered data-table">';
	htmlStr += '<tbody>';
	htmlStr += '<tr><td><span>流水单号：</span><span id="show_accountJourId"></span></td><td><span>账户代码：</span><span id="accountId"></span></td><td><span>申请时间：</span><span id="applyCommitTime"></span></td></tr>';
	htmlStr += '<tr><td><span>提现金额：</span><span id="amount"></span></td><td><span><span>手续费：</span><span id="fee"></span></td><td><span>申请方式：</span><span id="applyTypeName"></span></td></tr>';
	htmlStr += '<tr><td><span>持卡人名称：</span><span id="show_accountName"></span></td><td><span><span>银行：</span><span id="show_bankName"></span></td><td><span>卡号：</span><span id="show_bankNumber"></span></td></tr>';
	htmlStr += '<tr><td><span>申请人：</span><span id="show_createUserName"></span></td><td><span><span>处理时间：</span><span id="show_finishTime"></span></td><td>&nbsp;</td></tr>';
	htmlStr += '</tbody>';
	htmlStr += '</table>  	';
	htmlStr += '</div>';
	htmlStr += '</div> ';
	/*
	htmlStr += '<div class="widget-box">';
	htmlStr += '<div class="widget-title">';
	htmlStr += '<span class="icon"><i class="icon-th"></i></span>';
	htmlStr += '<h5>订单处理信息</h5>';
	htmlStr += '</div>        ';
	htmlStr += '<div class="widget-content nopadding dataTables_wrapper">';
	htmlStr += '<table class="table table-bordered data-table">';
	htmlStr += '<tbody>';
	htmlStr += '<tr><td><span>开始时间：</span><span id="reqBankTime"></span></td><td><span>结算类型：</span><span id="operationName"></span></td><td><span>完成时间：</span><span id="finishBankTime"></span></td></tr>';
	htmlStr += '</tbody>';
	htmlStr += '</table>  	';
	htmlStr += '</div>';
	htmlStr += '</div>  ';
	*/
	htmlStr += '</div>';
	htmlStr += '</div> ';
	htmlStr += '</div>'; 
	
	showDiv("content1")
	
	$("#content1").html(htmlStr);
	
	var params={
				
				"accountJourId":selectAccountJourId
				
		        };
	
	base.showLoading();

	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.account.getAccountDetail,params));
		
		loadAccountDetailCallBack(data);
		
	}))().start();
		
		
}

/**
 * 账户流水详情回调函数
 */
function loadAccountDetailCallBack(data){

	var htmlStr="";

	if(data["code"]==1){
		
		if(data["applystautusId"]!=null){
			if(data["applystautusId"]=="2"){
				$("#applystautusname").html("<font color='00C618' size='2px'>"+data["applystautusname"]+"</font>");
			}else{
				$("#applystautusname").html("<font color='red' size='2px'>"+data["applystautusname"]+"</font>");
			}
		}else{
			$("#applystautusname").html("");
		}
		
		if(data["settleResultId"]!=null){
			if(data["settleResultId"]=="1"){
				$("#settleresult").html("<font color='00C618' size='2px'>"+data["settleresult"]+"</font>");
			}else{
				$("#settleresult").html("<font color='red' size='2px'>"+data["settleresult"]+"</font>");
			}
		}else{
			$("#settleresult").html("");
		}
		
		$("#show_accountJourId").html(data["accountJourId"]);
		$("#accountId").html(data["accountId"]);
		$("#applyCommitTime").html(data["applyCommitTime"]);
		$("#amount").html(data["amount"]);
		$("#fee").html(data["fee"]);
		$("#applyTypeName").html(data["applyTypeName"]);
		
		$("#show_accountName").html(data["accountName"]);
		$("#show_bankName").html(data["bankName"]);
		$("#show_bankNumber").html(data["bankNumber"]);
		$("#show_createUserName").html(data["createUserName"]);
		$("#show_finishTime").html(data["finishTime"]);
		
		//$("#reqBankTime").html(data["reqBankTime"]);
		//$("#operationName").html(data["operationName"]);
		//$("#finishBankTime").html(data["finishBankTime"]);

	}else{

		base.tips_error(data["message"]);

	}

	base.cancelLoading();

}


/**
 * 设置固定日期范围
 * @param _value
 */
function toQueryDate(_value) { 
	
	
	queryDate=_value;
	
	//设置固定日期的样式
	for (var i = 0; i < 6; i++) {
		$("#queryDate_" + i).removeClass("btn-primary"); 
	}
	
	$("#queryDate_" + queryDate).addClass("btn-primary");
	
}





/**
 * 流水类型列表
 */
function getOperTypeList(){
	
	eval(Wind.compile("async",function(){
		
		var data = $await(wind_async.DDF_AsyncRequest("POST",ddf.account.getQueryOperType,""));
		
		getOperTypeListCallBack(data);
		
	}))().start();
}

/**
 * 流水类型列表_回调函数
 */
function getOperTypeListCallBack(data){
	
	
	var htmlStr="";
	
	for(var i=0;i<data["operTypeListData"].length;i++){
		
		htmlStr+='<li><a href=javascript:$ddf_account.setOperTypeId("'+data["operTypeListData"][i]["OPERATION_CODE"]+'","'+data["operTypeListData"][i]["OPERATION"]+'")>'+data["operTypeListData"][i]["OPERATION"]+'</a></li>';
		
	}
	
	$("#orderTypeList").html('<li><a href=javascript:$ddf_account.setOperTypeId("","请选择")>请选择</a></li>'+htmlStr);
	
}

/**
 * 设置流水类型
 */
function setOperTypeId(_operTypeId,operTypeName){
	
	operType=_operTypeId;
	
	$("#orderTypeName").html(operTypeName);
	
}

/**
 * 设置查询范围
 */
function setKeyRange(_keyRange,keyRangeName){
	
	keyRange=_keyRange;
	
	$("#keyRangeName").html(keyRangeName);
	
}


/**
 * 显示DIV
 */
function showDiv(block){
	
	$("#content > div").hide();
	
	if($("#"+block).length<=0){
		
		$("#content").append('<div id="'+block+'"></div>'); 
		
	}else{
		
		$("#"+block).show();
	}
	
	if(block=="content0"){
		shopTypeId="";
	}
	
}



//暴露方法
exports.getAccountList=getAccountList;
exports.resetSearchParams=resetSearchParams;
exports.searchAccount=searchAccount;
exports.loadAccountDetail=loadAccountDetail;
exports.toQueryDate=toQueryDate;
exports.setOperTypeId=setOperTypeId;
exports.setKeyRange=setKeyRange;

exports.showDiv=showDiv;

});
